<include file="Common/header" />
<title>管理员管理</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form-user-character-add">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>登陆名：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" value="{$info['username']}" placeholder="" id="username" name="username" datatype="*4-16" nullmsg="用户账户不能为空">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>姓名：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" value="{$info['nickname']}" placeholder="" id="nickname" name="nickname" datatype="*4-16" nullmsg="用户账户不能为空">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>密码：</label>
			<div class="formControls col-10">
				<input type="password" class="input-text" value="" placeholder="" id="password" name="password" datatype="*4-16" nullmsg="用户账户不能为空">
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>角色权限：</label>
			<div class="formControls col-10"> 
				<span class="select-box">
					<select class="select" id="sel_Sub" name="sel_Sub" >
						<?php foreach($rolelist as $ls){ ?>
						<option value="{$ls['role_id']}" <?php echo $ls['role_id'] == $info['role_id'] ? 'selected' : ''; ?>>&nbsp;&nbsp;├&nbsp;{$ls['role_name']}</option>
						<?php } ?>
					</select>
				</span> 
			</div>
			<div class="col-3"> </div>
		</div>
		
		<input type="hidden" name="uuid" id="uuid" value="{$info['user_id']}" />
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</div>

<script>
	$(function(){
		$(".permission-list dt input:checkbox").click(function(){
			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
		});
		
		$(".permission-list2 dd input:checkbox").click(function(){
			var l =$(this).parent().parent().find("input:checked").length;
			var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
			if($(this).prop("checked")){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
			}
			else{
				if(l==0){
					$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
				}
				if(l2==0){
					$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
				}
			}
			
		});
		
		$(".submitBtn").on('click', function(){
			var data = {};
			var username = $("#username").val();
			if(username.length > 0 && username.length <= 20){
				data.username = username;
			}else{
				layer.msg('登陆帐号长度在2~20个字符之间。', {icon: 5, time: 2000});
				return false;
			}
			
			var nickname = $("#nickname").val();
			if(nickname.length > 0 && nickname.length <= 20){
				data.nickname = nickname;
			}else{
				layer.msg('姓名长度在2~20个字符之间。', {icon: 5, time: 2000});
				return false;
			}
			
			var password = $("#password").val();
			if(password.length > 0 && password.length <= 20){
				data.password = password;
			}else{
				layer.msg('密码长度在2~20个字符之间。', {icon: 5, time: 2000});
				return false;
			}
			
			data.role_id = $("#sel_Sub").val();
			data.uuid = $("#uuid").val();
			
			$.post('index.html', data, function(row){
				if(row/1){
					layer.msg('添加成功', {icon: 1, time: 2000}, function(){
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index);
						
						parent.location.reload()
					});
				}else{
					layer.msg('添加失败', {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>